<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-list-swipe.css" />
    <style>
        body {}
    </style>
</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
        <a class="aui-pull-left aui-btn" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle">
            任务单配送
        </div>
    </header>
    <div class="aui-content">

        <div class="aui-form">

            <div class="aui-input-row" style="font-size: 18px;">
                <span class="aui-input-addon"
                    style="width: 20%;text-align: left;font-size: 0.8rem;font-weight: 600;">配送任务号:</span>
                <input type="text" class='aui-input' placeholder="" style="width: 80%;" id="paTaskCode" />
                <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="searchTask()"></i>
            </div>

        </div>
        <div style="background-color:white; height: 100%;width: 100%;font-size: 16px;">
            <table style="width:100%;margin-left: 5px;">
                <tr>
                    <td style="width: 25%;">配送单号：</td>
                    <td id="code" colspan="3"></td>
                </tr>
                <tr>
                    <!-- <td style="width: 25%;">任务类型：</td>
                    <td id="taskType" style="width: 25%;"></td>
                    <td style="width: 25%;">任务状态：</td>
                    <td id="status" style="width: 25%;"></td> -->
                </tr>
                <tr>
                    <td style="width: 25%;">目标仓库：</td>
                    <td id="uda1c" style="width: 75%;"></td>

                </tr>
                <tr>
                    <td style="width: 25%;">调入库位：</td>
                    <td id="ext06" style="width: 75%;"></td>
                </tr>
                <tr>
                    <td style="width: 25%;">创建时间：</td>
                    <td id="createDate" colspan="3"></td>
                </tr>
            </table>

        </div>

        <div style="background-color:white; height: 100%;width: 100%;">

            <ul class="ui-selectee" id="tbodyHtml">

            </ul>
        </div>
    </div>

    <!-- <footer class="aui-bar aui-bar-tab" id="footer">
        <div id="yjzBtn" class="aui-btn aui-btn-info aui-btn-block" onclick="save()" style="display:none;">一键转库</div>
        <div id="yjcBtn" class="aui-btn aui-btn-info aui-btn-block" onclick="saveOUT()" style="display:none;">一键出库</div>
    </footer> -->

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/aui-list-swipe.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    apiready = function () {
        $("#paTaskCode").focus();
        idSelector = "paTaskCode";
    };

    var swipe = new ListSwipe();
    var paTaskCode = "";


    //扫描回车事件
    $("#paTaskCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {
            $("#paTaskCode").val(sm);
            getDistributeMrlInfo(sm);
        }
    });


    // 获取工配送任务单-对应的 物料需求信息
    function getDistributeMrlInfo(paTaskCode) {
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchDistributeMrlInfo";
        var params = new Object();
        params.url = url;
        params.method = 'post';
        params.dataType = 'json';
        var un = localStorage.getItem('un');
        var data = {
            values: {
                paTaskCode: paTaskCode,
                un: un
            }
        };
        console.log("un", un);
        api.showProgress({
            title: '查询中...',

        });
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                $("#paTaskCode").focus();
                idSelector = "paTaskCode";
                //返回成功
                if (myobj.code == "0") {
                    var list = myobj.list;
                    var stockUpType = myobj.stockUpType;//（业务参数配置）配送任务备货处理类型， 一键出库、一键转库、不处理
                    var mainData = myobj.mainData;
                    var code = mainData.code;
                    var workOrderCode = mainData.workOrderCode;
                    var uda1c = mainData.uda1c;
                    var uda2c = mainData.uda2c;

                    var ext06 = mainData.ext06;
                    var createDate = mainData.createDate;
                    var taskType = mainData.taskType;
                    var status = mainData.status;

                    workOrderCode = workOrderCode == null ? "" : workOrderCode;
                    uda2c = uda2c == null ? "" : uda2c;
                    if (status == '0') {
                        status = '未开始'
                    }
                    if (status == '1') {
                        status = '进行中'
                    }
                    if (status == '2') {
                        status = '已完成'
                    }
                    if (status == '3') {
                        status = '已取消'
                    }
                    $("#code").text(paTaskCode);
                    $("#ext06").text(ext06);
                    $("#uda1c").text(uda1c);
                    $("#createDate").text(createDate);
                    $("#taskType").text(taskType);
                    $("#status").text(status);
                    setTable(list, paTaskCode);

                } else if (myobj.code == "1") {
                    //失败
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });

    }



    function setTable(list, code) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            var uda1 = list[i].receiveQty;
            var bgColor = "#F5F5F5";
            uda1 = (uda1 == null || uda1 == undefined || uda1 == "") ? "0" : uda1;
            //console.log("countQty   " + Number(list[i].countQty));
            //console.log("uda1   " + Number(uda1));
            if (Number(list[i].countQty) > Number(uda1)) {
                //console.log("不满足");
                bgColor = "#FF5151";
            } else {
                //console.log("满足");
                bgColor = "#00BB00";
            }
            uda1 = (uda1 == null || uda1 == undefined || uda1 == "") ? "0" : uda1;
            html += "<div style='padding-top:4%;'></div>";
            html += "<li class='sortable ui-selectee ui-sortable' >";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item  ui-selectee' style='color: black !important;background-color:" + bgColor + " !important;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee' >";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料号:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'  style='color:#000000;'>" + list[i].mrlCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style='color:#000000; word-wrap:break-word; overflow:hidden;'>" + list[i].mrlName + "</div>";
            html += "</div>";
            // html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            // html += "<div class='aui-list-item-label ui-selectee list-tr-title'>理论数量:</div>";
            // html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].predictQty + "</div>";
            // html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>计算数量:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style='color:#000000;'>" + list[i].countQty + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'style = 'word-break:break-all'>已备货数量:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style='color:#000000;'>" + uda1 + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'style = 'word-break:break-all'></div>";
            html += "<div class='aui-list-item-inner ui-selectee' style='color:#000000;'></div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background:#d0d0d0;color:#000000;' onclick='goDetailPge(\"" + list[i].mrlCode + "\",\"" + code + "\",\"" + list[i].mrlName + "\");'>查看</div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background:#d0d0d0;color:#000000;' onclick='goDetailBHPge(\"" + list[i].mrlCode + "\",\"" + code + "\",\"" + list[i].mrlName + "\");'>备货</div>";
            html += "</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtml"), html);
    };

    //跳转任务明细页面
    function goDetailPge(mrlCode, paTaskCode, mrlName) {
        var url = "paAndonDistribute-detail.html";
        api.openWin({
            name: 'paAndonDistribute-detail',
            url: 'paAndonDistribute-detail.html',
            pageParam: {
                paTaskCode: paTaskCode,
                mrlName: mrlName,
                mrlCode: mrlCode
            }
        });
    }


    //跳转备货页面
    function goDetailBHPge(mrlCode, paTaskCode, mrlName) {
        var url = "paAndonDistribute-detail-bh.html";
        api.openWin({
            name: 'paAndonDistribute-detail-bh',
            url: 'paAndonDistribute-detail-bh.html',
            pageParam: {
                paTaskCode: paTaskCode,
                mrlName: mrlName,
                mrlCode: mrlCode
            }
        });
    }


    function createPaTaskDetail(str) {
        // var obj = document.getElementById("code");
        // var paTaskCode = obj.innerText;//$("#code").val();

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/createPaTaskDetail";
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                paTaskCode: str,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                console.log(JSON.stringify(myobj));
                //成功
                if (myobj.code == '0') {

                    api.hideProgress();

                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                } else {
                    api.hideProgress();
                    if (myobj.message != 'EE') {
                        api.toast({
                            msg: myobj.message,
                            duration: 3000
                        });
                    }

                }
            }
        });


    }

    function searchTask() {
        api.openWin({
            name: 'paSearchTask',
            url: 'paSearchTask.html',
            pageParam: {
                name: "paAndonDistribute"
            }
        });
    }

    function setPaTaskCode(str) {
        $("#paTaskCode").val(str);
        getDistributeMrlInfo(str);
        createPaTaskDetail(str);

    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }


</script>

</html>